<?php

	$usrnm = $_GET['usrnm'];
	$sessionToken = $_GET['sessionKey'];
	
	//$con = mysql_connect("localhost","user1789586","adobephotoshopcs5");
	$con = mysql_connect("localhost","root");
	
	if(!$con)
		die("could not connect ".mysql_error());
		
	mysql_select_db("db1789586-main",$con);
	
	$query = 'Select * FROM sessioinDetails WHERE usrnm="'.$usrnm.'"';
	
	$result = mysql_query($query);
	
	$count = 0;
	
	while($row = mysql_fetch_array($result)){
		$count++;
		if($sessionToken == $row['sessionKey'])
			$count++;
	}
	
	if($count == 0){
		$arr = array('result'=>'NotLoggedIn');
	}
	else if($count == 1){
		$arr = array('result'=>'InvalidSessionKey');
	}
	else if($count == 2){
		$query = 'Select * FROM usrdetails WHERE usrnm="'.$usrnm.'"';
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result)){
			$arr = array('result'=>'success');
			
			$usrDetails = array('usrnm' => $row['usrnm']);
			$usrDetails['fname'] = $row['fname'];
			$usrDetails['lname'] = $row['lname'];
			$usrDetails['sex'] = $row['sex'];
			$usrDetails['dob'] = $row['dob'];
			
			$arr['content'] = $usrDetails;
		}
	}
	
	echo json_encode($arr);
?>